package com.lsfb.signln.Login.Forget;

import android.content.Intent;
import android.view.View;
import android.widget.EditText;

import com.lsfb.signln.Login.LoginActivity;
import com.lsfb.signln.R;
import com.lsfb.signln.Utils.LittleUtils;
import com.lsfb.signln.Utils.URLString;
import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.OnClick;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.T;

import java.util.HashMap;

/**
 * Created by Administrator on 2018/1/23 0023.
 */
@ContentView(R.layout.aty_forget_pwd)
public class ForgetPwdActicity extends LsfbActivity {

    /**
     * 密码
     */
    @ViewInject(R.id.aty_forget_et_pwd)
    private EditText et_pwd;

    private String code;
    private String phone;

    @Override
    public void initView() {
        code = getIntent().getStringExtra("code");
        phone = getIntent().getStringExtra("phone");
    }

    @Override
    public void initEvent() {

    }

    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.aty_forget_img_back, R.id.aty_forget_post})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.aty_forget_img_back:
                finish();
                break;
            case R.id.aty_forget_post:
                resetPwd();
                break;
        }
    }

    @Override
    public void initData() {

    }

    /**
     * 重置密码
     */
    public void resetPwd() {
        if (et_pwd.getText().toString().isEmpty()) {
            T.showShort(this, "请输入密码");
            return;
        }
        HashMap<String, String> hashMap = new HashMap<String, String>();
        hashMap.put("phone", phone);
        hashMap.put("checkcode", code);
        hashMap.put("password", et_pwd.getText().toString());
        new BaseInternet().getData(URLString.RESETPWD, hashMap, String.class, new ResetPwdEvent(), false);
    }

    @EventAnnotation
    public void ResetPwdEvent(ResetPwdEvent event) {
        switch (event.getCode()) {
            case 200:
                startActivity(new Intent(this, LoginActivity.class));
                finish();
                break;
            case 1006:
                T.showShort(this, "您的账号已在其它设备登录，请重登录");
                LittleUtils.exit(this);
                startActivity(new Intent(this, LoginActivity.class));
                break;
            default:
                T.showShort(this, event.getMsg());
                break;
        }
    }

}
